/*
 *   Clovis
 *   Copyright (C) 2008 SFWOL
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef __CONVERTER_H
#define __CONVERTER_H

#include <iostream>
#include <string>
#include <sstream>
#include <cmath>

#include "CInteger.h"
#include "CFloat.h"
#include "CString.h"

namespace clovis {

	namespace core {

		/*!
		 * Converter is a class who can convert a lot of formats into others (types, values, ...)
		 * Converter cannot be instanciated.
		 */
		class Converter {

			public:

				/*!
				 * Convert a CInteger value to an hexadecimal value (as CString)
				 * \arg value The CInteger value.
				 * \return The converted value (as CString)
				 * \todo TODO !!!
				 */
				static CString toHex(CInteger value, bool with_prefixe = false);

				/*!
				 * Convert an hexadecimal value (in a CString) to a CInteger.
				 * \arg The value to convert (could be like 'ff' or '0xff')
				 * \return The result of the conversion.
				 */
				static CInteger fromHex(CString value);

				/*!
				 * Calcul the percent that represents the given value in the given scale.
				 * \arg value The value we wants to calculate the percent it represents.
				 * \arg scale_start The start of the scale where is the value.
				 * \arg scale_end The end of the scale where is the value.
				 * \return A percent value.
				 */
				static CFloat toPercent(CFloat value, CFloat scale_start, CFloat scale_end);

				/*!
				 * Convert a pointer of ClovisVariable to another type
				 * \arg type of target
				 */
                template<class T>
                static T * convertClovisVariable( ClovisVariable * toConvert ){
                    try{
                        T * tmp = dynamic_cast<T*>(toConvert);
                        return tmp;
                    }catch ( const std::bad_alloc & ){
                        std::cout << "Oups!\n";
                    }

                }
		};

	};

};

#endif
